package io.github.junxworks.qt.utils;

import java.util.List;
import java.util.function.Consumer;

public class BatchUtils {
	public static <T> void batchHandle(List<T> objs, int batchSize, Consumer<List<T>> consumer) {
		for (int page = 1, index = 0, len = objs.size(); index < len; page++) {
			int toIndex = page * batchSize;
			if (toIndex >= len) {
				toIndex = len;
			}
			consumer.accept(objs.subList(index, toIndex));
			index = toIndex;
		}
	}
}
